#include <vector>
#include "Core/Log/LogManager.h"
#include "Core/Time/TimeMeasure.h"
#include "Core/Memory/MemoryPoolManager.h"
#include "MemorySpeedTest.h"

const char * MemorySpeedTest::GetName() const
{
	return "Memory Speed Test";
}

void MemorySpeedTest::Execute()
{
	{
		// To initialize and allocate MemoryPool used to perform the measures
		A1 * e=new A1;
		B1 * f=new B1;
		C1 * g=new C1;
		delete e;
		delete f;
		delete g;
	}



	LOG_INFO("- Speed Memory Test");
	TimeMeasure tm;

	tm.AddMeasure();
	std::vector<A1*> vA(200);
	std::vector<B1*> vB(200);
	std::vector<C1*> vC(200);
	std::vector<A2*> vA2(200);
	std::vector<B2*> vB2(200);
	std::vector<C2*> vC2(200);
	tm.Start(0);
	for(int j=0; j<3; j++)
	{
		for(uint32 i=0; i<200; ++i)
		{
			vA[i]=new A1;
			vB[i]=new B1;
			vC[i]=new C1;
		}
		for(uint32 i=0; i<200; ++i)
		{
			delete vA[i];
			delete vB[i];
			delete vC[i];
		}
	}
	tm.Stop(0);

	LOG_INFO("  With Memory Pool : %.3f ms", tm.GetMeasure(0));

	tm.AddMeasure();

	tm.Start(1);
	for(int j=0; j<3; j++)
	{
		for(uint32 i=0; i<200; ++i)
		{
			vA2[i]=new A2;
			vB2[i]=new B2;
			vC2[i]=new C2;
		}
		for(uint32 i=0; i<200; ++i)
		{
			delete vA2[i];
			delete vB2[i];
			delete vC2[i];
		}
	}
	tm.Stop(1);

	LOG_INFO("  Without Memory Pool : %.3f ms", tm.GetMeasure(1));
}
